﻿Public Class Record_Put
    'PutData(ctlContent(i), ctlType(i), CByte(i))
    Public Shared Function PutData(ByVal varData As String, ByVal btDataType As Byte, Optional ByRef jFldNr As Byte = 254) As String
        jFldNr = jFldNr + 1

        'output: [fldNumber] & fldType & [fldLen] & fldContent
        Dim fLen As Integer
        Dim ss, sFldNr As String
        ss = ""
        ' determine field number, if 255 then it will be added by calling procedure
        If jFldNr < 255 Then
            sFldNr = Chr(jFldNr)
        Else
            sFldNr = ""
        End If

        Select Case btDataType
            Case 10, 12 'dbText, dbMemo   '10,12 all strings
                fLen = Len(varData)
                Select Case fLen
                    'Case 0
                    Case Is < 255 'text
                        ss = Chr(btDataType) & Chr(fLen) & varData
                    Case Is > 65000
                        varData = Left(varData, 65000)
                        fLen = 65000
                        ss = Chr(btDataType) & Chr(255) & Chr(fLen Mod 256) & Chr(fLen \ 256) & varData
                    Case Else 'memo >255
                        ss = Chr(btDataType) & Chr(255) & Chr(fLen Mod 256) & Chr(fLen \ 256) & varData
                End Select
            Case Else
                ss = Chr(btDataType) & varData
        End Select
        MessageBox.Show(ss)
        ' add fieldNumber
        If ss.Length > 0 Then
            Return sFldNr & ss
        Else
            Return ""
        End If
    End Function
End Class
